package org.fight.landowner.remoting.exception;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author wangxuehao02
 * @Date 2024/2/22 7:51 PM
 * @Description
 **/
public class RemotingRequestExceptionFactory {

    private static final Map<Integer, RemotingRequestException> EXCEPTION_MAP = new HashMap<>(RemotingRequestExceptionType.values().length);

    static {
        for (RemotingRequestExceptionType exceptionType : RemotingRequestExceptionType.values()) {
            EXCEPTION_MAP.put(exceptionType.getCode(), new RemotingRequestException(exceptionType.getCode(), exceptionType.getMessage()));
        }
    }

    public static RemotingRequestException getRemotingRequestExceptionByCode(int code) {
        return EXCEPTION_MAP.getOrDefault(code, EXCEPTION_MAP.get(RemotingRequestExceptionType.UNKNOWN_EXCEPTION.getCode()));
    }
}
